﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.ComponentModel;
using Sora.HelpSystem.Package.Pages;

namespace Sora.HelpSystem.Editor.Converters
{
    public class EditablePageItemWrapperConverter : IValueConverter
    {
        class WrappedEditablePageItem : INotifyPropertyChanged
        {
            public HelpPage Page { get; private set; }

            public WrappedEditablePageItem(HelpPage page)
            {
                if(page == null)
                    Page = null;
                else
                {
                    Page = page;
                    Page.PropertyChanged += delegate
                    {
                        RaisePropertyChanged("Page");
                    };
                }
            }

            #region INotifyPropertyChanged Members

            public event PropertyChangedEventHandler PropertyChanged;

            private void RaisePropertyChanged(string property)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(property));
            }

            #endregion
        }


        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return new WrappedEditablePageItem(value as HelpPage);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
